//
//  tstPtPcell.swift
//  Tinsecret_TW
//
//  Created by wanghui on 2018/10/31.
//  Copyright © 2018年 tst. All rights reserved.
//

import UIKit

class tstPtPcell: UITableViewCell {
    
    private let imgWidth: CGFloat = 50
    private let imgHeight: CGFloat = 50
    //头像
    lazy var headimage: UIImageView = {
        let headImg = UIImageView.init()
        headImg.layer.cornerRadius = 5
        headImg.layer.masksToBounds = true
        contentView.addSubview(headImg)
        headImg.isUserInteractionEnabled = true
        headImg.backgroundColor = UIColor.clear
        headImg.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageClick)))
        headImg.backgroundColor = UIColor.gray
        return headImg
    }()
    
    lazy var headview: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.clear
        view.frame = CGRect.init(x: 0, y: 0, width: imgWidth, height: imgHeight)
        return view
    }()
    
    //名称
    lazy var nameLabel: UILabel = {
        let nlabel = UILabel.init()
//        nlabel.textColor = UIColor.black
//        nlabel.font = UIFont.systemFont(ofSize: 18.0)
        nlabel.textAlignment = .left
        nlabel.numberOfLines = 1
        contentView.addSubview(nlabel)
        return nlabel
    }()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.separatorInset  = UIEdgeInsets(top: 0, left: 70, bottom: 0, right: 0)
        
        //添加子view
        self.contentView.addSubview(headimage)
        self.contentView.addSubview(headview)
        self.contentView.addSubview(nameLabel)
//        self.backgroundColor = UIColor.white
        
        headimage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.width.height.equalTo(50)
        }
        
        headview.snp.makeConstraints { (make) in
            make.edges.equalTo(headimage)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(headimage.snp.right).offset(10)
            make.right.lessThanOrEqualToSuperview().offset(-10)
            make.height.equalTo(20)
        }
        
        self.selectionStyle = .gray
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func getLabWidth(labelStr:String,font:UIFont,height:CGFloat) -> CGFloat {
        
        let statusLabelText: NSString = labelStr as NSString
        
        let size = CGSize(width:900, height:height)
        
        let strSize = statusLabelText.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font:font], context: nil).size
        
        return strSize.width
        
    }
    @objc func imageClick(){
        print("1");
    }
}

